package xyz.liut.ee.filter

import jakarta.servlet.*
import jakarta.servlet.annotation.WebFilter
import xyz.liut.logcat.kt.logInfo
import java.io.IOException

@WebFilter(filterName = "ServerFilter", urlPatterns = ["/*"])
@Suppress("unused")
class WebServerFilter : Filter {

    @Throws(ServletException::class)
    override fun init(filterConfig: FilterConfig) {
        logInfo { "init() called with: filterConfig = [" + filterConfig.filterName + "]" }
    }

    @Throws(IOException::class, ServletException::class)
    override fun doFilter(request: ServletRequest, response: ServletResponse, chain: FilterChain) {
        logInfo {
            "$request from ${request.remoteAddr}"
        }
        chain.doFilter(request, response)
    }

    override fun destroy() {
        logInfo { "destroy() called" }
    }


}
